<?php

class Model_Exhibition extends Zend_Db_Table_Row
{
	
	public function getArtworks(){
		if ($this->artworks) {
			$table = new Model_DbTable_ArtWork();
			$artworks = $table->fetchAll("id IN ($this->artworks)");
			
			return $artworks;
		}else{
			return array();
		}
	}
	
	public function getJoinedArtists(){
		$artworks = $this->getArtworks();
		$joinedArtists = array();
		foreach ($artworks as $artwork){
			if (!isset($joinedArtists[$artwork->artist])){
				$joinedArtists[$artwork->artist] = $artwork->getArtistObj();
			}
		}
		
		return $joinedArtists;
	}
	
	public function getHomeCoverPhysicalPath($size=null) {
		$origFile = PUBLIC_PATH . '/images/exhibition_homepage_cover/' . $this->homepage_cover;
		if (empty($size)) {
			return $origFile;
		}
		$resizedFile = PUBLIC_PATH . '/images/artists_avar/' . $size . '_' . $this->homepage_cover;
		if (!file_exists($resizedFile) && is_readable($origFile)) {
			ImageHelper::resize($origFile, $resizedFile, $size);
		}
		return $resizedFile;
	}
	
	public function getHomeCoverWebAccessablePath($size=null) {
		if (empty($size)) {
			return '/images/exhibition_homepage_cover/' . $this->homepage_cover;
		}
		$this->getPhotoPhysicalPath($size);
		return '/images/artists_avar/' . $size . '_' . $this->homepage_cover;
	}


}

